<template>
  <div class="app-container">
    <el-form
      class="list-search"
      :model="queryParams"
      
      ref="queryRef"
      :inline="true"
      label-width="100"
    >
      <el-form-item label="请选择公司" prop="companyCode" v-if="user.userType != 2">
        <el-select
          v-model="queryParams.companyCode"
          placeholder="请选择公司"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in companyList"
            :key="dict.companyCode"
            :label="dict.companyName"
            :value="dict.companyCode"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="昵称" prop="nickName" >
        <el-input v-model="queryParams.nickName" placeholder="请输入昵称"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="contactNumber" >
        <el-input v-model="queryParams.contactNumber" placeholder="请输入手机号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="search()"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="refresh">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="用户ID" align="center" prop="id" />
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      <el-table-column label="联系电话" align="center" prop="contactNumber" />
      <el-table-column
        label="归属公司"
        v-if="user.userType != 2"
        align="center"
        prop="tel"
      >
        <template #default="{ row }">
          {{
            filterName(
              companyList,
              row.companyCode,
              "companyCode",
              "companyName"
            )
          }}
        </template>
      </el-table-column>
      <el-table-column label="用户头像" align="center" prop="userAvatarUrl" >
        <template #default="{ row }">
          <img class="userImg"   v-if="row.userAvatarUrl" :src="VITE_APP_BASE_API + row.userAvatarUrl" alt="" />
        </template>
      </el-table-column>

      <el-table-column
        label="注册时间"
        align="center"
        prop="registrationTime"
      />
    </el-table>
  </div>
</template>

<script setup name="WebsiteRecord">
import { queryWxUserInfoUser, queryBasicCompany } from "@/api/website/index";
import useUserStore from "@/store/modules/user";
let user = useUserStore();
let VITE_APP_BASE_API = import.meta.env.VITE_APP_BASE_API;
let loading = ref(false);
let dataList = ref([]);
let queryParams = ref({
  pageNum: 1,
  pageSize: 10,
});

let companyList = ref([]);
function getCompanyList() {
  queryBasicCompany({
    pageNum: 1,
    pageSize: 999,
  }).then((res) => {
    companyList.value = res.rows;
  });
}
getCompanyList();
// 获取页面列表
let total = ref(0);
function getList() {
  loading.value = true;
  queryWxUserInfoUser(queryParams.value)
    .then((res) => {
      dataList.value = res.rows;
      total.value = res.total;
      loading.value = false;
    })
    .catch((err) => {
      loading.value = false;
    });
}
getList();
let open = ref(false);
function search() {
  queryParams.value.pageNum = 1;
  getList();
}
function refresh() {
  queryParams.value.pageNum = 1;
  queryParams.value.companyCode = "";
  queryParams.value.contactNumber = "";
  queryParams.value.nickName = "";
  getList();
}
</script>

<style scoped lang="scss">
.userImg {
  width: 50px;
  height: 50px;
}
.list_item {
  color: #333;
  .ans {
    padding: 10px 30px;
  }
}
</style>
